import com.alibaba.druid.pool.DruidDataSource;

import java.sql.SQLException;

public class Main {
    public static void main(String[] args) {
        //创建Druid数据源
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/jdbc");
        dataSource.setUsername("root");
        dataSource.setPassword("3390956");
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setInitialSize(10);
        dataSource.setMaxActive(20);
        dataSource.setMinIdle(5);
        dataSource.setMaxWait(6000);
        dataSource.setValidationQuery("select 1");
        dataSource.setTestOnBorrow(true);

        try{
            if(dataSource.getConnection()!=null){
                System.out.println("连接成功");
            }else{
                System.out.println("连接失败");
            }
            }catch (SQLException e){
            throw new RuntimeException(e);
        }

    }
}